package com.hollycrm.sipdemo.sip;

import org.pjsip.pjsua2.*;

/**
 * Created by aber on 2017/3/2.
 */

class UIPBuddy extends Buddy {
    public BuddyConfig cfg;

    UIPBuddy(BuddyConfig config) {
        super();
        cfg = config;
    }

    String getStatusText()
    {
        BuddyInfo bi;
        try {
            bi = getInfo();
        } catch (Exception e) {
            return "?";
        }
        String status = "";
        if (bi.getSubState() == pjsip_evsub_state.PJSIP_EVSUB_STATE_ACTIVE) {
            if (bi.getPresStatus().getStatus() ==
                    pjsua_buddy_status.PJSUA_BUDDY_STATUS_ONLINE) {
                status = bi.getPresStatus().getStatusText();
                if (status == null || status.length()==0) {
                    status = "Online";
                }
            } else if (bi.getPresStatus().getStatus()
                    == pjsua_buddy_status.PJSUA_BUDDY_STATUS_OFFLINE) {
                status = "Offline";
            } else {
                status = "Unknown";
            }
        }
        return status;
    }

    @Override
    public void onBuddyState() {
        UIPApp.observer.notifyBuddyState(this);
    }

}
